import request from '@/utils/http.js'

 const appkey = 'U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA='

// 注册

export const register = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/register',
		data
	})
}

// 登录

export const login = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/login',
		data
	})
}

// 获取用户信息

export const getUserInfo = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findMy',
		params
	})
}

/*
	获取用户全部信息 
	params: {
		appkey,
		tokenString
	}
*/

export const getUserInfoAll = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findAccountInfo',
		params
	})
}

/*
	上传用户背景图片 
	query: {
		appkey,
		tokenString
		imgType
		serverBase64Img
	}
*/

export const updateUserBg = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/updateUserBg',
		data
	})
}

/*
	上传用户头像 
	query: {
		appkey,
		tokenString
		imgType
		serverBase64Img
	}
*/

export const updateUserAvatar = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/updateAvatar',
		data
	})
}

/*
	修改用户昵称 
	query: {
		appkey,
		tokenString,
		nickName
	}
*/

export const updateNickName = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/updateNickName',
		data
	})
}

/*
	修改用户简介 
	query: {
		appkey,
		tokenString,
		desc
	}
*/

export const updateDesc = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/updateDesc',
		data
	})
}

/*
	获取我的收藏
	params: {
		appkey,
		tokenString
	}
*/

export const findAllLike = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findAllLike',
		params
	})
}

/*
	修改用户密码 
	query: {
		appkey,
		tokenString,
		oldPassword,
		password
	}
*/

export const updatePassword = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/updatePassword',
		data
	})
}

/*
	注销账户
	query: {
		appkey,
		tokenString
	}
*/

export const destroyAccount = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/destroyAccount',
		data
	})
}
